/*!
 * FileName: luogu-3366.cpp
 * This Problem is on luogu. The ID of the problem is 3366. 
 * Copyright(c) 2019 Shu_Yu_Mo
 * MIT Licensed
 * Luogu: https://www.luogu.org/space/show?uid=44615
 * Github: https://github.com/oldsuold/
 * Gitee: https://gitee.com/Shu_Yu_Mo/
 * These words were created by an amazing tool written by Shu_Yu_Mo.
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int _ = 5100;
inline int read()
{
    char c = getchar(); int sign = 1; int x = 0;
    while(c > '9' || c < '0') { if(c=='-')sign = -1; c = getchar(); } 
    while(c <= '9' && c >= '0') { x *= 10; x += c - '0'; c = getchar(); }
    return x * sign;
}
int n, m;
int g[_][_];
int Min[_];
bool vis[_];
int main()
{
	n = read(), m = read();
	memset(Min, 0x7f, sizeof(Min));
	memset(g, 0x7f, sizeof(g));
	memset(vis, false, sizeof(vis));
	Min[1] = 0;
	for(register int i = 1;i <= m;i++)
	{
		int tmpx = read(), tmpy = read(),tmpz = read();
		g[tmpy][tmpx] = g[tmpx][tmpy] = min(g[tmpx][tmpy], tmpz);
	}
	for(register int i = 1;i <= n;i++)
	{
		int k = 0;
		for(register int j = 1;j <= n;j++)
		{
			if(!vis[j] && Min[k] > Min[j])
				k = j;
		}
//		printf("find %d\n", k);
		vis[k] = true;
		for(register int j = 1;j <= n;j++)
			if(!vis[j] && Min[j] > g[k][j])
				Min[j] = g[k][j];
	}
	int total = 0;
	bool flag = true;
//	for(register int i = 1;i <= n;i++)
//		printf("%d : %d\n", i, Min[i]);
	for(register int i = 1;i <= n;i++) 
	{
		total += Min[i];
		if(Min[i] == 0x7f7f7f7f) 
		{
			flag = false;
			break;
		}
	}
	if(flag)
		cout<<total<<endl;
	else
	puts("orz");
    return 0;
}





















